//
//  MainViewController.m
//  音悦咖
//
//  Created by Best on 15/7/13.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "MainViewController.h"

#import "D_UserBarViewController.h"
#import "D_LocalMusicViewController.h"
#import "L_RecommendBarViewController.h"

#import "D_DataBase.h"
#import "L_SongListViewController.h"
#import "D_BgImageViewController.h"
#import "LoginViewController.h"
#import "L_AsiaNewSongWebView.h"
#import "L_Singleton.h"
#import "C_RecentSkimPlayerViewController.h"
#import "C_NewSongViewController.h"

@interface MainViewController () <MusicViewControllerDelegate,UIScrollViewDelegate,UIScrollViewDelegate,L_RecommendBarViewControllerDelegate,D_UserBarViewControllerDelegate,UIAlertViewDelegate>

@property (nonatomic, retain ) UIImageView *headImg;
@property (nonatomic, retain) UILabel *login;
@property (nonatomic, retain) L_Singleton *single;
@property (nonatomic, retain) L_FootPlayVIew *footPlayView;

 
@end

@implementation MainViewController
- (void)dealloc

{
    [_footPlayView release];
    [_single release];
    [_login release];
    [_headImg release];
    [_scrollImage release];
    [_blackImageView release];
    [_slidingBlock release];
    [_backGroundView release];
    [_naviBarView release];
    [_musicBarButton release];
    [_drawerBarButton release];
    [_recommendBarButton release];
    [_SearchBarButton release];
    [_userBarButton release];
    [_mainScroll release];
    [_mainView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = YES;
    

    
#pragma mark - 侧边栏scroll
    
    self.mainScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, -20, SCREEN_WIDTH, SCREEN_HEIGHT + 20)];
    self.mainScroll.backgroundColor = [UIColor grayColor];
    
    self.mainScroll.contentSize = CGSizeMake(SCREEN_WIDTH + SCREEN_WIDTH * 0.8, 0);
    self.mainScroll.pagingEnabled = YES;
    self.mainScroll.delegate = self;
    self.mainScroll.tag = 10;
    self.mainScroll.bounces = YES;
    
    // 侧边栏背景图片(最底层scroll图片)
    self.scrollImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH + SCREEN_WIDTH * 0.8, SCREEN_HEIGHT)];
    self.scrollImage.alpha = 0.6;
    self.scrollImage.image = [UIImage imageNamed:@"img17.jpg"];
    [self.mainScroll addSubview:self.scrollImage];
    self.mainScroll.scrollEnabled = YES;
    [_scrollImage release];
    
    
#pragma mark -  mainScroll 上的视图
    self.mainScroll.contentOffset = CGPointMake(SCREEN_WIDTH * 0.8, 0);
    self.mainScroll.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:self.mainScroll];
   
    // mainView  mainScroll 上的视图
    self.mainView = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.8, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.mainScroll addSubview:self.mainView];
    
    [_mainView release];
   
    [self createMainView];
    [self createMainScroll];
    
#pragma mark - 创建数据库
    
    D_DataBase *dbManager = [D_DataBase shareInstance];
    // 打开数据库
    [dbManager openDB];
    
    [dbManager createTable];
//    [dbManager deleteAllTable];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 创建NaviBar
- (void)createMainView
{

    
  

    // 背景图片
    self.backGroundView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49)];
    self.backGroundView.image = [UIImage imageNamed:@"img17.jpg"];
    [self.mainView addSubview:self.backGroundView];
    
    [_backGroundView release];
//    //navi 背景图片
//    
//    self.blackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
//    [self.mainView addSubview:self.blackImageView];
//    self.blackImageView.image = [UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"musicbg", @"jpg")];
//    self.blackImageView.userInteractionEnabled = YES;
//    [_blackImageView release];
    // NaviView
    self.naviBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    self.naviBarView.backgroundColor = [UIColor clearColor];
    
    [self.mainView addSubview:self.naviBarView];
    [_naviBarView release];
    
    // 导航栏背景颜色
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH , 64)];
    lab.layer.borderWidth = 2;
    lab.alpha = 0.4;
    lab.layer.borderColor = [UIColor grayColor].CGColor;
    [lab.layer setCornerRadius:10];
    lab.backgroundColor = [UIColor grayColor];
    [self.naviBarView addSubview:lab];
    
    CGFloat height = self.naviBarView.frame.size.height - 3;
    CGFloat width = SCREEN_WIDTH / 5;
    
    //DrawerBarButton
    self.drawerBarButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.drawerBarButton setImage:[UIImage imageNamed:@"drawer"] forState:(UIControlStateNormal)];
    self.drawerBarButton.frame = CGRectMake(0, 10, width, height);
    [self.drawerBarButton addTarget:self action:@selector(drawerBarButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.naviBarView addSubview:self.drawerBarButton];
    
    [_naviBarView release];
    
    //UserButton
    self.userBarButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.userBarButton setTitle:@"我的" forState:(UIControlStateNormal)];
     [self.userBarButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [self.naviBarView addSubview:self.userBarButton];
    self.userBarButton.frame = CGRectMake(self.drawerBarButton.bounds.origin.x + self.drawerBarButton.frame.size.width, self.drawerBarButton.frame.origin.y, self.drawerBarButton.frame.size.width, self.drawerBarButton.frame.size.height);
    [self.userBarButton addTarget:self action:@selector(userBarButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
    //RecommendBarButton
    self.recommendBarButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.recommendBarButton setTitle:@"推荐" forState:(UIControlStateNormal)];
     [self.recommendBarButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.recommendBarButton.frame = CGRectMake(self.userBarButton.frame.origin.x + self.userBarButton.frame.size.width, self.userBarButton.frame.origin.y, self.userBarButton.frame.size.width, self.userBarButton.frame.size.height);
    [self.naviBarView addSubview:self.recommendBarButton];
    [self.recommendBarButton addTarget:self action:@selector(recommendBarButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
    //MusicBarButton
    self.musicBarButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.musicBarButton setTitle:@"乐酷" forState:(UIControlStateNormal)];
    [self.musicBarButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.musicBarButton.frame = CGRectMake(self.recommendBarButton.frame.origin.x + self.recommendBarButton.frame.size.width, self.userBarButton.frame.origin.y, self.userBarButton.frame.size.width, self.userBarButton.frame.size.height);
    [self.naviBarView addSubview:self.musicBarButton];
    [self.musicBarButton addTarget:self action:@selector(musicBarButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
    
    //SearchBarButton
    self.SearchBarButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.SearchBarButton setImage:[UIImage imageNamed:@"search.png"] forState:UIControlStateNormal];
    [self.SearchBarButton addTarget:self action:@selector(SearchBarButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.SearchBarButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    self.SearchBarButton.frame = CGRectMake(self.musicBarButton.frame.origin.x + self.musicBarButton.frame.size.width, self.userBarButton.frame.origin.y, self.userBarButton.frame.size.width, self.userBarButton.frame.size.height);
    [self.naviBarView addSubview:self.SearchBarButton];
    
    // 小滑块
    self.slidingBlock = [[UIView alloc] initWithFrame:CGRectMake(self.userBarButton.frame.origin.x, self.naviBarView.frame.size.height - 3, self.userBarButton.frame.size.width, 3)];
    self.slidingBlock.backgroundColor = [UIColor whiteColor];
    [self.naviBarView addSubview:self.slidingBlock];
    [_slidingBlock release];
    
    
    // 抽屉
    [self drawer];
    
   
}


#pragma mark - 抽屉
- (void)drawer
{
    // 头像
    self.headImg = [[UIImageView alloc ] initWithFrame:CGRectMake(SCREEN_WIDTH * 0.32, SCREEN_HEIGHT * 0.075, 80, 80)];
    self.headImg.backgroundColor = [UIColor whiteColor];
    [self.headImg.layer setCornerRadius:40];
    self.headImg.image = [UIImage imageNamed:@"lloo"];
    self.headImg.userInteractionEnabled = YES;
    [self.headImg setClipsToBounds:YES];
    self.headImg.alpha = 0.8;
 
   

    
    
    [_headImg release];
   
    [self.mainScroll addSubview:self.headImg];

    
    // 背景图片
    UIButton *bgImg = [UIButton buttonWithType:UIButtonTypeSystem];
    bgImg.frame = CGRectMake(SCREEN_WIDTH * 0.13, SCREEN_HEIGHT * 0.27, SCREEN_WIDTH * 0.32, SCREEN_HEIGHT * 0.075);
    bgImg.backgroundColor = [UIColor whiteColor];
    [bgImg.layer setCornerRadius:10];
    bgImg.alpha = 0.8;
    [bgImg setBackgroundImage:[UIImage imageNamed:@"bgimg"] forState:UIControlStateNormal];
    [bgImg setClipsToBounds:YES];
    [bgImg addTarget:self action:@selector(bgImgAction) forControlEvents:UIControlEventTouchUpInside];
    [self.mainScroll addSubview:bgImg];
    
    // 删除缓存
    UIButton *deletRela = [UIButton buttonWithType:UIButtonTypeSystem];
    deletRela.frame = CGRectMake(SCREEN_WIDTH * 0.35, SCREEN_HEIGHT * 0.405, SCREEN_WIDTH * 0.32, SCREEN_HEIGHT * 0.075);
    deletRela.backgroundColor = [UIColor whiteColor];
    [deletRela.layer setCornerRadius:10];
    deletRela.alpha = 0.8;
    [deletRela setBackgroundImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
    [deletRela setClipsToBounds:YES];
    [deletRela addTarget:self action:@selector(deletRelaAction) forControlEvents:UIControlEventTouchUpInside];
    [self.mainScroll addSubview:deletRela];
    
    // 版本
    UIButton *edition = [UIButton buttonWithType:UIButtonTypeSystem];
    edition.frame = CGRectMake(SCREEN_WIDTH * 0.133, SCREEN_HEIGHT * 0.54, SCREEN_WIDTH * 0.32, SCREEN_HEIGHT * 0.075);
    edition.backgroundColor = [UIColor whiteColor];
    [edition.layer setCornerRadius:10];
    edition.alpha = 0.8;
    [edition setBackgroundImage:[UIImage imageNamed:@"edition"] forState:UIControlStateNormal];
    [edition setClipsToBounds:YES];
    [edition addTarget:self action:@selector(editionAction) forControlEvents:UIControlEventTouchUpInside];
    [self.mainScroll addSubview:edition];
    
    // 关于我们
    UIButton *abuoutMy = [UIButton buttonWithType:UIButtonTypeSystem];
    abuoutMy.frame = CGRectMake(SCREEN_WIDTH * 0.37, SCREEN_HEIGHT * 0.675, SCREEN_WIDTH * 0.32, SCREEN_HEIGHT * 0.075);
    abuoutMy.backgroundColor = [UIColor whiteColor];
    [abuoutMy.layer setCornerRadius:10];
    abuoutMy.alpha = 0.8;
    [abuoutMy setBackgroundImage:[UIImage imageNamed:@"aboutMy"] forState:UIControlStateNormal];
    [abuoutMy setClipsToBounds:YES];
    [abuoutMy addTarget:self action:@selector(abuoutMyAction) forControlEvents:UIControlEventTouchUpInside];
    [self.mainScroll addSubview:abuoutMy];
    
    
    
}


#pragma mark - 背景图片
- (void)bgImgAction
{
    BOLOCK setImg = ^(NSInteger num) {
        NSArray *arr = [@[@"img1.jpg",@"img2.jpg",@"img3.jpg",@"img4.jpg",@"img5.jpg",@"img6.jpg",@"img7.jpg",@"img8.jpg",@"img9.jpg",@"img10.jpg",@"img11.jpg",@"img12.jpg",@"img13.jpg",@"img14.jpg",@"img15.jpg",@"img16.jpg",@"bg.jpg",@"img18.jpg",@"img19.jpg",@"img20.jpg"] mutableCopy];
            self.backGroundView.image = [UIImage imageNamed:arr[num]] ;
            self.scrollImage.image = [UIImage imageNamed:arr[num]];
    };
    D_BgImageViewController *bgImg = [[D_BgImageViewController alloc]init];
    bgImg.block = setImg;
    [self.navigationController pushViewController:bgImg animated:YES];
    
}
#pragma mark - 删除缓存
- (void)deletRelaAction
{
    UIAlertView *aler = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选择要删除的内容!" delegate:self cancelButtonTitle:@"清理播放列表" otherButtonTitles:@"清理本地内存", nil];
    aler.delegate = self;
    [aler show];
    [aler release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        
        NSArray *array = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
        NSString *path = [array lastObject];
        path = [NSString stringWithFormat:@"%@/Caches",path];
        NSLog(@"%@",path);
        [self clearCache:path];
        
//        NSLog(@"Library下Caches文件夹内容已清除");
    }else{
        D_DataBase *data = [[D_DataBase alloc] init];
        [data openDB];
        [data deleteTable];
    }
    
    
}
//清除文件
-(void)clearCache:(NSString *)path{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:path]) {
        NSArray *childerFiles=[fileManager subpathsAtPath:path];
        for (NSString *fileName in childerFiles) {
            //如有需要，加入条件，过滤掉不想删除的文件
            NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
            [fileManager removeItemAtPath:absolutePath error:nil];
        }
    }
    [[SDImageCache sharedImageCache] cleanDisk];
}
#pragma mark - 版本
- (void)editionAction
{
    D_BanBenViewController *banben = [[D_BanBenViewController alloc]init];
    [self.navigationController pushViewController:banben animated:YES];
}
-(void)abuoutMyAction
{
    D_AboutOurViewController *abuoutMy = [[D_AboutOurViewController alloc]init];
    [self.navigationController pushViewController:abuoutMy animated:YES];
}

#pragma mark - 创建主页底部ScrollView
- (void)createMainScroll
{
    //主页面 UIScrool
    scroll = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49)] autorelease];
    scroll.backgroundColor = [UIColor clearColor];
    scroll.contentSize = CGSizeMake(SCREEN_WIDTH * 3, 0);
    scroll.directionalLockEnabled = YES;
    scroll.pagingEnabled = YES;
    scroll.showsHorizontalScrollIndicator = NO;
    scroll.tag = 1000;
    [self.view addSubview:scroll];
  

    // 音乐库页面
    music = [[MusicViewController alloc] initMusicView];
    music.delegate = self;
    [scroll addSubview:music.mainCollection];
   
    scroll.delegate = self;
    [self.mainView addSubview:scroll];


    // 我的页面
    
    D_UserBarViewController *user = [[D_UserBarViewController alloc]init];
    user.view.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49);
    user.delegate = self;
    [scroll addSubview:user.view];


    // 推荐页面
    L_RecommendBarViewController *recommendBar = [[L_RecommendBarViewController alloc] init];
    recommendBar.delegate = self;
    recommendBar.Posterdelegate = self;
    recommendBar.view.frame = CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49);
    [scroll addSubview:recommendBar.view];


    
}

#pragma mark CirclePush 界面方法
- (void)MusicViewControllerPushViewWithCollectionView:(UICollectionView *)collection ItemAtIndexPath:(NSInteger)indexPath NewSongURL:(NSString *)url

{
    switch (indexPath) {
        case 1: {
           
            C_NewSongViewController *new = [[C_NewSongViewController alloc] init];
            new.NewSong_url = url;
            [self.navigationController pushViewController:new animated:YES];
            
            break;
        }
        case 2: {
            C_RankingListViewController *rank = [[C_RankingListViewController alloc] init];
            rank.rankingURL = url;
            [self.navigationController pushViewController:rank animated:YES];
            break;
        }
        case 3: {
            C_SongerViewController *rank = [[C_SongerViewController alloc] init];
            rank.songer_url = url;
            [self.navigationController pushViewController:rank animated:YES];
            break;
        }
        case 4: {
            C_MVViewController *rank = [[C_MVViewController alloc] init];
            rank.MV_url = url;
            [self.navigationController pushViewController:rank animated:YES];
            break;
        }
        case 5: {
            C_RedioViewController *rank = [[C_RedioViewController alloc] init];
            rank.redio_url = url;
            [self.navigationController pushViewController:rank animated:YES];
        
            break;
        }
        case 6: {
            C_SongClassifyViewController *rank = [[C_SongClassifyViewController alloc] init];
            rank.song_url = url;
            [self.navigationController pushViewController:rank animated:YES];
            break;
        }
        default:
            break;
    }
}

#pragma mark Recent协议方法

- (void)RecentSkimListPlayerWithModel:(C_RecentSkimModel *)model
{
    
  

          C_RecentSkimPlayerViewController *player = [[C_RecentSkimPlayerViewController alloc] init];
          player.URL = model.recent_url;
    
    [self.navigationController pushViewController:player animated:YES];
    
    
}



#pragma mark - RecommendBarPush代理协议方法
-(void)L_RecommendBarViewControllerPushViewController:(NSIndexPath *)indexPath SongId:(NSString *)songId
{
   
    if (indexPath.section == 1 && indexPath.item == 0) {
        C_NewSongViewController *songClassify = [[[C_NewSongViewController alloc] init] autorelease];
        songClassify.NewSong_url = @"http://online.dongting.com/recomm/new_songs_more?page=1&size=30&app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPhone7%2C1&f=f320&s=s310&imsi=&hid=&splus=8.3&active=1&net=2&openudid=07afc257564998d95c30d3961b852009acbd4bc7&idfa=344D8202-B8A1-4025-8A03-D1D21F9B1723&utdid=VZ9EyvXI9JADAKFnFQwx0zo5&alf=201200&bundle_id=com.ttpod.music";
        [self.navigationController pushViewController:songClassify animated:YES];
        
    } else if (indexPath.section == 5 && indexPath.item == 0){
        
        L_AsiaNewSongWebView *Asia = [[L_AsiaNewSongWebView alloc] init];
        [self.navigationController pushViewController:Asia animated:YES];
        
    }else if (indexPath.section == 3 && indexPath.item == 0) {
        L_GuessYouLoveViewController *guess = [[L_GuessYouLoveViewController alloc] init];
        [self.navigationController pushViewController:guess animated:YES];
        
    }else {
    
    L_SongListViewController *l = [[[L_SongListViewController alloc] init] autorelease];
        l.songId = songId;
    [self.navigationController pushViewController:l animated:YES];
        
    }

}

- (void)L_RecommendBarViewControllerPushViewController:(NSIndexPath *)indexPath Url:(NSString *)url
{
    if (indexPath.section == 5 && indexPath.item == 0) {
        L_AsiaNewSongWebView *Asia = [[L_AsiaNewSongWebView alloc] init];
        Asia.value = url;
        [self.navigationController pushViewController:Asia animated:YES];
    }
}

#pragma mark - 推荐页面轮播图push代理方法
- (void)L_PosterPushViewController:(NSInteger)index Action:(NSDictionary *)action
{
    NSLog(@"type: %@", [action objectForKey:@"type"]);
    if ([[NSString stringWithFormat:@"%@", action[@"type"]] isEqualToString:@"1"]) {
    
        
        L_AsiaNewSongWebView *webView = [[L_AsiaNewSongWebView alloc] init];
        webView.value = [action objectForKey:@"value"];
        [self.navigationController pushViewController:webView animated:YES];
    } else if ([[NSString stringWithFormat:@"%@", action[@"type"]] isEqualToString:@"5"]){
        
    L_SongListViewController *l = [[[L_SongListViewController alloc] init] autorelease];
        l.songId = [action objectForKey:@"value"];
    [self.navigationController pushViewController:l animated:YES];
    }
}


#pragma mark - 我的按钮点击方法
- (void)userBarButtonAction
{
    scroll.contentOffset = CGPointMake(SCREEN_WIDTH * 0,0);
    self.slidingBlock.frame = CGRectMake(self.userBarButton.frame.origin.x, self.naviBarView.frame.size.height - 3, self.userBarButton.frame.size.width, 3);
    
}

#pragma mark - 推荐按钮点击方法
- (void)recommendBarButtonAction
{
    scroll.contentOffset = CGPointMake(SCREEN_WIDTH * 1,0);
    self.slidingBlock.frame = CGRectMake(self.recommendBarButton.frame.origin.x, self.naviBarView.frame.size.height - 3, self.userBarButton.frame.size.width, 3);
}

#pragma mark - 乐库按钮点击方法
- (void)musicBarButtonAction
{
    scroll.contentOffset = CGPointMake(SCREEN_WIDTH * 2,0);
    self.slidingBlock.frame = CGRectMake(self.musicBarButton.frame.origin.x, self.naviBarView.frame.size.height - 3, self.userBarButton.frame.size.width, 3);
    
}

#pragma mark - 抽屉 button.selected = !button.selected;

- (void)drawerBarButtonAction:(UIButton *)button
{
    button.selected = !button.selected;
    if (button.selected) {
        [UIView animateWithDuration:0.3 animations:^{
            [self.mainScroll setContentOffset:CGPointMake(0, -20)];
            self.mainView.transform = CGAffineTransformMakeScale(0.9, 0.9);
            
        } completion:^(BOOL finished) {
            // 执行结束 后执行的方法
            
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            [self.mainScroll setContentOffset:CGPointMake(SCREEN_WIDTH * 0.8, -20)];
            self.mainView.transform = CGAffineTransformMakeScale(1, 1);
        }];
        
    }
}

#pragma mark - 搜索
- (void)SearchBarButtonAction:(UIButton *)button
{
    SearchViewController *search = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:search animated:YES];
}

#pragma mark - 滑块滑动方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // 侧边栏抽屉效果
    if (scrollView.tag == 10 && scrollView.contentOffset.x < 200) {
        [UIView animateWithDuration:0.2 animations:^{
            self.mainView.transform = CGAffineTransformMakeScale(0.9, 0.9);
            
        }];
    }else{
        [UIView animateWithDuration:0.2 animations:^{
        self.mainView.transform = CGAffineTransformMakeScale(1, 1);
        }];
            }

    [self.userBarButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [self.recommendBarButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
     [self.musicBarButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    NSInteger index = scroll.contentOffset.x/ SCREEN_WIDTH;
    self.slidingBlock.frame = CGRectMake(scroll.contentOffset.x / SCREEN_WIDTH * self.userBarButton.frame.size.width + self.userBarButton.frame.size.width, self.naviBarView.frame.size.height - 3, self.userBarButton.frame.size.width, 3);
    switch (index) {
        case 0:
            [self.userBarButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
            break;
            
        case 1:
            [self.recommendBarButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
            break;
            
        case 2:
            [self.musicBarButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
            break;
            
        default:
            break;
    }
    
}

#pragma mark - 底部播放视图tap手势方法
- (void)footPlayTapAction
{
    PlayViewController *play = [[[PlayViewController alloc] init] autorelease];
    
    
    [self presentViewController:play animated:YES completion:^{
        // 模态到音乐播放页面
    }];
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void)D_UserBarViewControllerPushViewController:(NSString *)num
{
    if ([num isEqualToString:@"0"]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        login.str = @"0";
        [self.navigationController pushViewController:login animated:YES];
    }else{
        
        D_LocalMusicViewController *local = [[D_LocalMusicViewController alloc]init];
        local.num = num;
        [self.navigationController pushViewController:local animated:YES];
    }
    
   
}
- (void)viewWillAppear:(BOOL)animated
{
    [music getrecentArrData];
    [music.mainCollection reloadData];
}

@end
